#pragma once

#include "src/base/noncopyable.h"

#include <condition_variable>
#include <functional>
#include <mutex>
#include <thread>

namespace sola {
namespace net {

class EventLoop;

class EventLoopThread : noncopyable {
public:
    typedef std::function<void(EventLoop*)> ThreadInitCallback;

    EventLoopThread(const ThreadInitCallback& cb = ThreadInitCallback(), const std::string& name = std::string());
    ~EventLoopThread();
    EventLoop* startLoop();

private:
    void threadFunc();

    EventLoop*              loop_; // GUARDED_BY(mutex_);
    bool                    exiting_;
    std::thread             thread_;
    mutable std::mutex      mutex_;
    std::condition_variable cond_; // GUARDED_BY(mutex_);
    ThreadInitCallback      callback_;
};

} // namespace net
} // namespace sola
